﻿using System;
using System.Linq;
using ScrumPilot.Domain.BPL;
using ScrumPilot.Helpers;

// ReSharper disable CheckNamespace
namespace ScrumPilot.Domain
// ReSharper restore CheckNamespace
{
// ReSharper disable InconsistentNaming
    public partial class user
// ReSharper restore InconsistentNaming
    {
        public int[] FilterListByProject
        {
            get
            {
                var v = GetExtendValue("prjctsflt");
                return !String.IsNullOrWhiteSpace(v) ? v.FromJSON() : null;
            }
            set { SetExtendedValue("prjctsflt", value.ToJSON()); }
        }

        public Boolean FilterListToDo
        {
            get { return Helper.GetValue<Boolean>(GetExtendValue("FilterListToDo")); }
            set { SetExtendedValue("FilterListToDo", value.ToString().ToLower()); }
        }

        public Boolean FilterListInProgress
        {
            get { return Helper.GetValue<Boolean>(GetExtendValue("FilterListInProgress")); }
            set { SetExtendedValue("FilterListInProgress", value.ToString()); }
        }

        public Boolean FilterListToTest
        {
            get { return Helper.GetValue<Boolean>(GetExtendValue("FilterListToTest")); }
            set { SetExtendedValue("FilterListToTest", value.ToString()); }
        }

        public Boolean FilterListDone
        {
            get { return Helper.GetValue<Boolean>(GetExtendValue("FilterListDone")); }
            set { SetExtendedValue("FilterListDone", value.ToString()); }
        }

        public Boolean FilterListReopen
        {
            get { return Helper.GetValue<Boolean>(GetExtendValue("FilterListReopen")); }
            set { SetExtendedValue("FilterListReopen", value.ToString()); }
        }

        public Boolean FilterListTask
        {
            get { return Helper.GetValue<Boolean>(GetExtendValue("FilterListTasks")); }
            set { SetExtendedValue("FilterListTasks", value.ToString()); }
        }

        public Boolean FilterListUserStory
        {
            get { return Helper.GetValue<Boolean>(GetExtendValue("FilterListUserStory")); }
            set { SetExtendedValue("FilterListUserStory", value.ToString()); }
        }

        public Boolean FilterListBug
        {
            get { return Helper.GetValue<Boolean>(GetExtendValue("FilterListBug")); }
            set { SetExtendedValue("FilterListBug", value.ToString()); }
        }

        public Boolean FilterListUnestimated
        {
            get { return Helper.GetValue<Boolean>(GetExtendValue("FilterListUnestimated")); }
            set { SetExtendedValue("FilterListUnestimated", value.ToString()); }
        }

        public Boolean FilterUsersList
        {
            get { return Helper.GetValue<Boolean>(GetExtendValue("FilterUsersList")); }
            set { SetExtendedValue("FilterUsersList", value.ToString()); }
        }

        public YammerUserParameters YammerUserParameters
        {
            get { return GetExtendValue("YammerUserParameters"); }
            set { SetExtendedValue("YammerUserParameters", value.ToString()); }
        }

        private String GetExtendValue(string sCode)
        {
            string sRet = null;
            if (userprofiles.Count > 0)
            {
                var t = userprofiles.FirstOrDefault(p => p.upkey == sCode);
                if (t != null)
                    sRet = t.upstringvalue;
            }
            return sRet;
        }

        private void SetExtendedValue(string sCode, string value)
        {
            var t = userprofiles.FirstOrDefault(p => p.upkey == sCode);
            if (t != null)
                t.upstringvalue = value;
            else
                userprofiles.Add(new userprofile { upkey = sCode, upstringvalue = value, upbinaryvalue = new byte[0] });
        }

    }
}
